package com.kingwood.algorithm.test;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @Author 22025812
 * @Description: 动态规划专题2
 * @Date: 2024/3/8 13:35
 * @Modified By：
 * @Version 1.0
 */
public class DongTaiGuiHua2 {

    /**
     * 获取最低花费 Wonderland
     * https://fcqian.blog.csdn.net/article/details/135328637
     * @param costs
     * @param days
     * @return
     */
    public static int getMinCosts(int[] costs, int[] days) {
        // 最大游玩日
        int maxDay = days[days.length - 1];
        int[] dp = new int[maxDay + 1];
        int index = 0;

        for (int i = 1; i <= maxDay; i++) {
            if (i == days[index]) {
                int buy1 = dp[i-1] + costs[0];
                int buy3 = (i >= 3 ? dp[i - 3] : 0) + costs[1];
                int buy7 = (i >= 7 ? dp[i - 7] : 0) + costs[2];
                int buy30 = (i >= 30 ? dp[i - 30] : 0) + costs[3];

                dp[i] = Math.min(buy1, Math.min(buy3, Math.min(buy7, buy30)));
                index++;
            } else {
                dp[i] = dp[i - 1];
            }
        }

        return dp[maxDay];
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] costs = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int[] days = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();

        System.out.println(getMinCosts(costs, days));
    }
}
